class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


def ln_to_int(x: ListNode) -> int:
    """
    从单链转换成一个整数
    """
    res = 0
    while x is not None:
        res = res * 10 + x.val % 10
        x = x.next
    return res


def int_to_ln(x: int) -> ListNode:
    """
    从一个整数生成单链
    """
    if x == 0:
        return ListNode(0)
    pre = None
    while x > 0:
        cur = ListNode(x % 10)
        cur.next = pre
        pre = cur
        x //= 10
    return pre


def ln_to_list(x: ListNode) -> list:
    """
    从单链转换成一个列表
    """
    res = []
    while x is not None:
        res.append(x.val)
        x = x.next
    return res


def list_to_ln(x: list) -> ListNode:
    """
    从一个列表生成单链
    """
    # pre = None
    # while len(x) > 0:
    #     cur = ListNode(x.pop())
    #     cur.next = pre
    #     pre = cur
    # return pre
    head = point = ListNode(0)
    for i in x:
        point.next = ListNode(i)
        point = point.next
    return head.next


if __name__ == '__main__':
    list_to_ln([1, 2, 3])
